package com.lukstron.youko;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.widget.Toast;

public class YoukoActivity extends Activity {

	protected PowerManager _powerManager = null;
	protected WakeLock _wakeLock = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
	}

	public void acquireWakeLock() {
		_powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
		int wakeLock = PowerManager.SCREEN_DIM_WAKE_LOCK;
		_wakeLock = _powerManager.newWakeLock(wakeLock, "GeoRes");
		_wakeLock.acquire();
	}

	public void releaseWakeLock() {
		if (_wakeLock.isHeld()) {
			_wakeLock.release();
		}
	}

	public static Boolean hasSd(Context context) {
		String auxSDCardStatus = Environment.getExternalStorageState();
		String s = null;

		if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED))
			return true;
		else if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
			s = "Warning, the SDCard it's only in read mode.\n"
					+ "this does not result in malfunction "
					+ "of the read aplication";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return true;
		} else if (auxSDCardStatus.equals(Environment.MEDIA_NOFS)) {
			s = "Error, the SDCard can be used, it has not a corret format "
					+ "or is not formated.";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return false;
		} else if (auxSDCardStatus.equals(Environment.MEDIA_REMOVED)) {
			s = "Error, the SDCard is not found, to use the reader you "
					+ "need insert a SDCard on the device.";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return false;
		} else if (auxSDCardStatus.equals(Environment.MEDIA_SHARED)) {
			s = "Error, the SDCard is not mounted beacuse is using "
					+ "connected by USB. Plug out and try again.";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return false;
		} else if (auxSDCardStatus.equals(Environment.MEDIA_UNMOUNTABLE)) {
			s = "Error, the SDCard cant be mounted.\nThe may be happend "
					+ "when the SDCard is corrupted or crashed.";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return false;
		} else if (auxSDCardStatus.equals(Environment.MEDIA_UNMOUNTED)) {
			s = "Error, the SDCArd is on the device but is not mounted."
					+ "Mount it before use the app.";
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();
			return false;
		}

		return true;
	}
}